package com.example.alarm.ui;

import java.util.Calendar;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.example.alarm.Config;
import com.example.alarm.R;
import com.example.alarm.bl.AlarmHelper;
import com.example.alarm.bl.MediaManager;
import com.example.alarm.bl.PreferencesManager;
import com.example.alarm.ui.receiver.AlarmReceiver;

public class AlarmActivity extends Activity {

	Button mSnoozeButton, mEndAlarmButton;
	boolean isButtonPressed;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_alarm);
		MediaManager.getInstance().stop();
		MediaManager.getInstance().play();
		initViews();
		initClicks();
		isButtonPressed=false;
		AlarmHelper.setSnooze();
	}

	private void initClicks() {
		mSnoozeButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				MediaManager.getInstance().stop();
				isButtonPressed=true;
				AlarmHelper.setSnooze();
				finish();
			//	alarmManager.setRepeating(, triggerAtMillis, intervalMillis, operation)
			}
		});

		mEndAlarmButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				isButtonPressed=true;
				MediaManager.getInstance().stop();
				AlarmHelper.setAlarm();
				finish();
			}
		});
	}

	private void initViews() {
		mSnoozeButton = (Button) findViewById(R.id.bt_snooze);
		mEndAlarmButton = (Button) findViewById(R.id.bt_end_alarm);
	}

	@Override
	protected void onPause() {
		super.onPause();
		MediaManager.getInstance().stop();
		if(!isButtonPressed){
			AlarmHelper.setSnooze();
		}
	}
}
